<template>
	<view class="container">
		<view class="submit" @click="submit">
			<image src="../../static/submit.png" mode=""></image>
		</view>
		<text class="text">日期:{{date}}</text>
		<view class="enter">
			<text class="text">天气:</text>
			<input type="text" value="" placeholder="请输入" id="input" v-model="weather"/>
		</view>
		<view class="enter">
			<text class="text">心情:</text>
			<input type="text" value="" placeholder="请输入" id="input" v-model="motion"/>
		</view>
		<input type="text" value="" placeholder="标题" id="title" v-model="title"/>
		<textarea placeholder="开始撰写今天的日记..." placeholder-style="" maxlength="-1" adjust-position="true" confirm-type="done" v-model="content"/>
	</view>
</template>

<script>
	export default{
		data(){
			return{
                key:'',
				title:'',
				content:'',
				weather:'',
				motion:'',
				date:new Date().toISOString().slice(0, 10),
			}
		},
        onLoad(){
            let res=uni.getStorageSync('daily-menu');
            let data=uni.getStorageSync('data');
            res=res.toString().split('');
            res.splice(0,1);
            res.splice(res.length-1,1);
            res=res.join('');
            res=JSON.parse(res);
            data=JSON.parse(data);
            this.weather=data.weather;
            this.motion=data.motion;
            this.title=res.title;
            this.content=data.content;
        },
		methods:{
			submit:function(event) {
				if (this.title.trim() && this.content.trim()) {
                    uni.setStorage({
                        key: this.title,
                        data:
                        {
                            "weather":this.weather||" ",
                            "motion":this.motion||" ",
                            "content":this.content||" "
                        },
                        success: function (res) {
                            uni.navigateTo({
                                url: '/pages/index/index'
                               });
                            this.weather=" ";
                            this.motion=" ";
                            this.title=" ";
                            this.content=" ";
                        }
                    });
				} else {
					uni.showToast({
						icon: 'none',
						title: '请输入正确内容',
						duration: 2000
					});
				}
			}
        }
	}
</script>

<style>
	.container{
		margin-left: 10rpx;
	}
	.text{
		display: block;
		font-family: '楷体';
		margin-right: 130rpx;
		font-size: 36rpx;
		margin-bottom: 5rpx;
	}
	.enter{
		display: flex;
	}
	#input{
		margin-left:-120rpx;
	}
	#title{
		font-size: 40rpx;
		font-weight: bolder;
		margin-bottom: 5rpx;
	}
	.submit{
		width: 100%;
		height: 50rpx;
	}
	.submit image{
		display: block;
		width: 50rpx;
		height: 50rpx;
		margin: auto;
		margin-right: 0;
	}
</style>
